﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda IVerifyChecksumDataStruct</summary>
    public class IVerifyChecksumDataStruct : IDisposable
    {
        /// <summary>Trieda IVerifyChecksumItem</summary>
        public class IVerifyChecksumItem
        {
            public string SourceFileName;
            public string ChecksumType;
            public string UserChecksum;
            public string ChecksumFileName;
            public string ResultChecksum;
            public string ExpectedChecksum;

            /// <summary>Konstruktor</summary>
            public IVerifyChecksumItem()
            {
                SourceFileName = "";
                UserChecksum = "";
                ChecksumFileName = "";
                ChecksumType =  "";
                ResultChecksum = "";
                ExpectedChecksum = "";
            }

            /// <summary>Skopirovanie obsahu objektu</summary>
            /// <param name="pValue"></param>
            public void Assign(IVerifyChecksumItem pValue)
            {
                SourceFileName = pValue.SourceFileName;
                UserChecksum = pValue.UserChecksum;
                ChecksumFileName = pValue.ChecksumFileName;
                ChecksumType = pValue.ChecksumType;
                ResultChecksum = pValue.ResultChecksum;
                ExpectedChecksum = pValue.ExpectedChecksum;
            }
            /// <summary>Zmena nastavenia kontroly pomocou formulara</summary>
            public bool EditWithForm()
            {
                using (IFileExplorerForm_VerifyChecksum_ItemEdit F = new IFileExplorerForm_VerifyChecksum_ItemEdit())
                {
                    F.Value.Assign(this);
                    bool B = F.ShowDialog() == System.Windows.Forms.DialogResult.OK;
                    if (B) Assign(F.Value);
                    return B;
                }
            }
        }

        public System.Collections.Generic.List<IVerifyChecksumItem> Items; // Polozky na overenie

        /// <summary>Konstruktor</summary>
        public IVerifyChecksumDataStruct()
        {
            Items = new System.Collections.Generic.List<IVerifyChecksumItem>();
        }
        /// <summary>Destruktor</summary>
        public void Dispose()
        {
            if (Items != null)
            {
                Items.Clear(); Items = null;
            }
        }

        /// <summary>Zmena nastavenia kontroly pomocou formulara</summary>
        public bool EditWithForm()
        {
            using (IFileExplorerForm_VerifyChecksum F = new IFileExplorerForm_VerifyChecksum())
            {
                F.Value = this;
                return F.ShowDialog() == System.Windows.Forms.DialogResult.OK;
            }
        }

        /// <summary>Zaradenie polozky do zoznamu</summary>
        /// <param name="pSourceFileName">nazov zdrojoveho suboru</param>
        /// <param name="pChecksum">typ kontrolneho suctu</param>
        /// <param name="pUserChecksum">uzivatelsky kontrolny sucet</param>
        /// <param name="pChecksumFileName">subor s kontrolnym suctom</param>
        /// <returns>pozicia</returns>
        public int Add(string pSourceFileName, string pChecksumType, string pUserChecksum, string pChecksumFileName)
        {
            IVerifyChecksumItem I = new IVerifyChecksumItem(); // Vytvorim objekt
            I.ChecksumType = pChecksumType; // Ulozim hodnoty
            I.ChecksumFileName = pChecksumFileName;
            I.SourceFileName = pSourceFileName;
            I.UserChecksum = pUserChecksum;
            Items.Add(I); // Zaradim
            return Items.Count - 1; // Vratim poziciu
        }

        /// <summary>Test ci je zadana hodnota kandidatom na zadany typ kontrolneho suctu</summary>
        /// <param name="pType">typ</param>
        /// <param name="pValue">hodnota</param>
        /// <returns>true / false</returns>
        public static bool IsCandidate(string pType, string pValue)
        {
            switch (pType)
            {
                case "CRC32": return ICore.IsHexNumber(pValue) && (pValue.Length == 8);
                case "MD5": return ICore.IsHexNumber(pValue) && (pValue.Length == 32);
                case "SHA1": return ICore.IsHexNumber(pValue) && (pValue.Length == 40);
                case "SHA256": return ICore.IsHexNumber(pValue) && (pValue.Length == 64);
                case "SHA384": return ICore.IsHexNumber(pValue) && (pValue.Length == 96);
                case "SHA512": return ICore.IsHexNumber(pValue) && (pValue.Length == 128);
                default: return false; // Default je nie
            }
        }
        /// <summary>Extrahovanie hodnoty kontrolneho suctu a typu zo suboru</summary>
        /// <param name="pFileName">nazov suboru</param>
        /// <param name="pSourceFileName">zdrojovy subor</param>
        /// <param name="ResultChecksumType">nacitany typ</param>
        /// <param name="ResultChecksum">nacitana hodnota</param>
        /// <returns>true / false</returns>
        public static bool ExtractChecksumFromFile(string pFileName, string pSourceFileName, out string ResultChecksumType, out string ResultChecksum)
        {
            string Data;
            ResultChecksumType = ""; ResultChecksum = "";
            string SourceFN = IFileSystem.ExtractName(pSourceFileName); // Extrahujem nazov zdroja

            try
            {
                INodeList L = INodeList.CreateNodeList(IFileSystem.ExtractPath(pFileName)); // Vytvoim zoznam
                if (L == null) return false;
                using (L) // Nacitam cast suboru
                {
                    bool IsFolder;
                    L.BeginSourceCopyMode();
                    if (L.CopyMode_ReadFromTextFile(L.CopyMode_MakeRelative(pFileName, out IsFolder), 1024*1024, out Data) != 0) return false; // Chyba citania
                }

                string[] Lines = new string[2];
                using (System.IO.StringReader R = new System.IO.StringReader(Data))
                {
                    while (true)
                    {
                        string Line = R.ReadLine();
                        if (Line == null) break;
                        if (Line.StartsWith(";")) continue;
                        Line = Line.Trim(); // Vycistim

                        int I = Line.LastIndexOf(' ');
                        if (I == -1) continue; // Nespravny format
                        Lines[0] = Line.Substring(0, I).Trim(); Lines[1] = Line.Substring(I + 1).Trim();

                        if (string.Compare(Lines[0], SourceFN, true) == 0) // Potencionalny CRC32
                        {
                            if (IVerifyChecksumDataStruct.IsCandidate("CRC32", Lines[1]))
                            {
                                ResultChecksumType = "CRC32";
                                ResultChecksum = Lines[1];
                                return true; // Nasiel som CRC32
                            }
                            continue;
                        }

                        I = Line.LastIndexOf('*');
                        if (I == -1) continue; // Nespravny format
                        Lines[0] = Line.Substring(0, I).Trim(); Lines[1] = Line.Substring(I).Trim();

                        if (Lines[1].StartsWith("*")) // Potencionalne MD5, SHA1, SHA256, SHA384 a SHA512
                        {
                            if (string.Compare(Lines[1].Substring(1), SourceFN, true) == 0)
                            {
                                if (IVerifyChecksumDataStruct.IsCandidate("MD5", Lines[0]))
                                {
                                    ResultChecksumType = "MD5";
                                    ResultChecksum = Lines[0];
                                    return true; // Nasiel som MD5
                                }
                                if (IVerifyChecksumDataStruct.IsCandidate("SHA1", Lines[0]))
                                {
                                    ResultChecksumType = "SHA1";
                                    ResultChecksum = Lines[0];
                                    return true; // Nasiel som SHA1
                                }
                                if (IVerifyChecksumDataStruct.IsCandidate("SHA256", Lines[0]))
                                {
                                    ResultChecksumType = "SHA256";
                                    ResultChecksum = Lines[0];
                                    return true; // Nasiel som SHA256
                                }
                                if (IVerifyChecksumDataStruct.IsCandidate("SHA384", Lines[0]))
                                {
                                    ResultChecksumType = "SHA384";
                                    ResultChecksum = Lines[0];
                                    return true; // Nasiel som SHA384
                                }
                                if (IVerifyChecksumDataStruct.IsCandidate("SHA512", Lines[0]))
                                {
                                    ResultChecksumType = "SHA512";
                                    ResultChecksum = Lines[0];
                                    return true; // Nasiel som SHA512
                                }
                                continue;
                            }
                        }
                    }
                }

                return false; // OK
            }
            catch
            {
                return false; // Chyba
            }
        }
    }

    /// <summary>Trieda IFileExplorerForm_VerifyChecksum</summary>
    public class IFileExplorerForm_VerifyChecksum : IForm
    {
        public IVerifyChecksumDataStruct Value; // Objekt s informaciami

        protected IGroupBox FGrp; // Controls
        protected IButton FBtn_OK;
        protected IButton FBtn_Cancel;

        protected ILabel FLabel1;
        protected IListView FList;

        /// <summary>Konstruktor</summary>
        public IFileExplorerForm_VerifyChecksum()
        {
        }

        /// <summary>Metoda: OnCreateForm</summary>
        /// <returns>true / false</returns>
        protected override bool OnCreateForm()
        {
            if (!base.OnCreateForm()) return false; // Volam predchodcu

            // Inicializacia
            MinimizeBox = false; MaximizeBox = false; FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; ShowIcon = true; ShowInTaskbar = false; StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

            SetBounds(0, 0, 700, 340); System.Drawing.Size CS = ClientSize;
            Text = lang.FORM_EDIT_VERIFY_CHECKSUM_TEXT_1;

            // Vytvorim groupbox
            FGrp = new IGroupBox(); IControl.PlaceControl_Inside(FGrp, this, 10, 10, 10, 50);
            System.Drawing.Size CS1 = FGrp.ClientSize;

            FLabel1 = new ILabel(lang.FORM_EDIT_VERIFY_CHECKSUM_TEXT_4);
            FList = new IListView(); FList.FullRowSelect = true; FList.HideSelection = true; FList.MultiSelect = false;
            FList.CreateColumn(lang.FORM_EDIT_VERIFY_CHECKSUM_TEXT_5_1, 300, System.Windows.Forms.HorizontalAlignment.Left);
            FList.CreateColumn(lang.FORM_EDIT_VERIFY_CHECKSUM_TEXT_5_2, 100, System.Windows.Forms.HorizontalAlignment.Center);
            FList.CreateColumn(lang.FORM_EDIT_VERIFY_CHECKSUM_TEXT_5_3, 200, System.Windows.Forms.HorizontalAlignment.Left);
            FList.ShowItemToolTips = true;
            FList.ItemActivate += Event_ItemActivated;

            FGrp.Controls.AddRange(new System.Windows.Forms.Control[] { FLabel1, FList }); // Zaradim controls
            IControl.PlaceControl_Inside_LeftTop_LeftTop(FLabel1, FGrp, 10, 20);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FList, FLabel1, 0, 10, FGrp.ClientSize.Width - 20, FGrp.ClientSize.Height - FLabel1.Bottom - 20);

            // Vytvorim tlacidla
            FBtn_Cancel = new IButton(lang.FORM_EDIT_VERIFY_CHECKSUM_TEXT_3); IControl.PlaceControl_Outside_TopRight_RightBottom(FBtn_Cancel, FGrp, 0, 10); FBtn_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            FBtn_OK = new IButton(lang.FORM_EDIT_VERIFY_CHECKSUM_TEXT_2, Event_BtnOKClick); IControl.PlaceControl_Outside_TopRight_LeftTop(FBtn_OK, FBtn_Cancel, 0, 10);

            Controls.AddRange(new System.Windows.Forms.Control[] { FGrp, FBtn_OK, FBtn_Cancel }); // Zaradim do controls

            FillList(); // Vyplnim zoznam

            AcceptButton = FBtn_OK; CancelButton = FBtn_Cancel; FBtn_OK.Focus();
            return true; // Vsetko OK
        }

        /// <summary>Vyplnenie zoznamu</summary>
        protected void FillList()
        {
            FList.BeginCreate();
            foreach (IVerifyChecksumDataStruct.IVerifyChecksumItem I in Value.Items)
            {
                IListViewItem It = FList.AddItem("", I.SourceFileName, 0);
                It.SubItems[1].Text = I.ChecksumType;
                It.SubItems[2].Text = I.UserChecksum == "" ? I.ChecksumFileName : I.UserChecksum;
                It.ToolTipText = It.SubItems[0].Text;
            }
            FList.EndCreate(0);
        }
        /// <summary>Aktualizacia obsahu zoznamu</summary>
        protected void UpdateList()
        {
            int C = FList.ItemsCount;
            for (int i = 0; i < C; i++) // Aktualizujem vsetky polozky
            {
                IVerifyChecksumDataStruct.IVerifyChecksumItem Val = Value.Items[i];
                FList.Items[i].SubItems[0].Text = Val.SourceFileName;
                FList.Items[i].SubItems[1].Text = Val.ChecksumType;
                FList.Items[i].SubItems[2].Text = Val.ChecksumFileName == "" ? Val.UserChecksum : Val.ChecksumFileName;
            }
        }
        /// <summary>Kontrola validity udajov formulara</summary>
        /// <returns>true / false</returns>
        protected bool CheckForm()
        {
            for (int i = 0; i < Value.Items.Count; i++) // Kontrolujem vsetky polozky v zozname
            {
                if (Value.Items[i].ChecksumFileName != "") continue; // Je zadany subor?
                if (!IVerifyChecksumDataStruct.IsCandidate(Value.Items[i].ChecksumType, Value.Items[i].UserChecksum))
                {
                    IApp.ShowError(lang.FORM_EDIT_VERIFY_CHECKSUM_TEXT_6);
                    FList.SelectedIndex = i;
                    FList.Focus();
                    return false;
                }
            }
            return true; // OK
        }

        /// <summary>Event: Click pre tlacidlo OK</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_BtnOKClick(object pSender, EventArgs e)
        {
            if (!CheckForm()) return; // Skontrolujem
            DialogResult = System.Windows.Forms.DialogResult.OK; // OK
        }
        /// <summary>Event: ItemActivated</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_ItemActivated(object pSender, EventArgs e)
        {
            int I = FList.SelectedIndex;
            if (I == -1) return; // Ziadna vybrana polozka?
            if (Value.Items[I].EditWithForm()) UpdateList(); // Zobrazim editor a prenesiem vysledky do zoznamu
        }
    }

    /// <summary>Trieda IFileExplorerForm_VerifyChecksum_ItemEdit</summary>
    public class IFileExplorerForm_VerifyChecksum_ItemEdit : IForm
    {
        public IVerifyChecksumDataStruct.IVerifyChecksumItem Value; // Objekt pre editaciu

        protected IGroupBox FGrp; // Controls
        protected IButton FBtn_OK;
        protected IButton FBtn_Cancel;

        protected ILabel FLabel1;
        protected ITextBox FText_SourceFile;
        protected IButton FBtn_ChooseSource;
        protected ILabel FLabel2;
        protected IComboBox FCombo_ChecksumType;
        protected IRadioButton FRadio_UseOwn;
        protected ITextBox FText_OwnChecksum;
        protected IRadioButton FRadio_UseFile;
        protected ITextBox FText_ChecksumFile;
        protected IButton FBtn_ChooseChecksumFile;

        /// <summary>Konstruktor</summary>
        public IFileExplorerForm_VerifyChecksum_ItemEdit()
        {
            Value = new IVerifyChecksumDataStruct.IVerifyChecksumItem();
        }

        /// <summary>Metoda: OnCreateForm</summary>
        /// <returns>true / false</returns>
        protected override bool OnCreateForm()
        {
            if (!base.OnCreateForm()) return false; // Volam predchodcu

            // Inicializacia
            MinimizeBox = false; MaximizeBox = false; FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; ShowIcon = true; ShowInTaskbar = false; StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

            SetBounds(0, 0, 400, 330); System.Drawing.Size CS = ClientSize;
            Text = lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_1;

            // Vytvorim groupbox
            FGrp = new IGroupBox(); IControl.PlaceControl_Inside(FGrp, this, 10, 10, 10, 50);
            System.Drawing.Size CS1 = FGrp.ClientSize;

            FLabel1 = new ILabel(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_4);
            FText_SourceFile = new ITextBox(); FText_SourceFile.ReadOnly = true;
            FBtn_ChooseSource = new IButton(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_5, Event_BtnClick_ChooseSourceFile, false);
            FLabel2 = new ILabel(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_6);
            
            FCombo_ChecksumType = new IComboBox();
            System.Collections.Generic.List<string> L = IGenerateChecksumDataStruct.GetSupportedChecksumIDs();
            foreach (string S in L) FCombo_ChecksumType.AddItem(S, S);

            FRadio_UseOwn = new IRadioButton(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_7);
            FText_OwnChecksum = new ITextBox();
            FRadio_UseFile = new IRadioButton(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_8);
            FText_ChecksumFile = new ITextBox(); FText_ChecksumFile.ReadOnly = true;
            FBtn_ChooseChecksumFile = new IButton(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_5, Event_BtnClick_ChooseChecksumFile, false);

            FGrp.Controls.AddRange(new System.Windows.Forms.Control[] { FLabel1, FText_SourceFile, FBtn_ChooseSource, FLabel2, FCombo_ChecksumType, FRadio_UseOwn, FText_OwnChecksum, FRadio_UseFile, FText_ChecksumFile, FBtn_ChooseChecksumFile});
            IControl.PlaceControl_Inside_LeftTop_LeftTop(FLabel1, FGrp, 10, 20);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FText_SourceFile, FLabel1, 1, 6, CS1.Width - 99);
            IControl.PlaceControl_Outside_LeftTop_TopRight(FBtn_ChooseSource, FText_SourceFile, -1, 10, 70, FText_SourceFile.Height + 2);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FLabel2, FText_SourceFile, 0, 10);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FCombo_ChecksumType, FLabel2, 0, 8, CS1.Width - 20);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FRadio_UseOwn, FCombo_ChecksumType, 0, 10);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FText_OwnChecksum, FRadio_UseOwn, 0, 8, CS1.Width - 20);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FRadio_UseFile, FText_OwnChecksum, 0, 10);
            IControl.PlaceControl_Outside_LeftTop_LeftBottom(FText_ChecksumFile, FRadio_UseFile, 1, 6, CS1.Width - 99);
            IControl.PlaceControl_Outside_LeftTop_TopRight(FBtn_ChooseChecksumFile, FText_ChecksumFile, -1, 10, 70, FText_ChecksumFile.Height + 2);

            // Vytvorim tlacidla
            FBtn_Cancel = new IButton(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_3); IControl.PlaceControl_Outside_TopRight_RightBottom(FBtn_Cancel, FGrp, 0, 10); FBtn_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            FBtn_OK = new IButton(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_2, Event_BtnOKClick); IControl.PlaceControl_Outside_TopRight_LeftTop(FBtn_OK, FBtn_Cancel, 0, 10);

            Controls.AddRange(new System.Windows.Forms.Control[] { FGrp, FBtn_OK, FBtn_Cancel }); // Zaradim do controls

            FRadio_UseFile.CheckedChanged += Event_CheckedChanged;
            FRadio_UseOwn.CheckedChanged += Event_CheckedChanged;

            FillForm(Value); // Vyplnim okno

            AcceptButton = FBtn_OK; CancelButton = FBtn_Cancel; FBtn_OK.Focus();
            return true; // Vsetko OK
        }

        /// <summary>Aktualizacia stavu okna</summary>
        protected void UpdateFormState()
        {
            FText_OwnChecksum.Enabled = FRadio_UseOwn.Checked;
            FText_ChecksumFile.Enabled = FRadio_UseFile.Checked;
            FBtn_ChooseChecksumFile.Enabled = FRadio_UseFile.Checked;
        }
        /// <summary></summary>
        /// <param name="pValue"></param>
        protected void FillForm(IVerifyChecksumDataStruct.IVerifyChecksumItem pValue)
        {
            FText_SourceFile.Text = pValue.SourceFileName;
            FCombo_ChecksumType.SelectedStringID = pValue.ChecksumType;
            FText_OwnChecksum.Text = pValue.UserChecksum;
            FText_ChecksumFile.Text = pValue.ChecksumFileName;
            FRadio_UseFile.Checked = pValue.ChecksumFileName != "";
            FRadio_UseOwn.Checked = !FRadio_UseFile.Checked;
            UpdateFormState();
        }
        /// <summary>Test validity dat formulara</summary>
        /// <returns>true / false</returns>
        protected bool CheckForm()
        {
            if (IFileSystem.GetObjectType(FText_SourceFile.Text) != IFileSystem.OBJECT_TYPE_FILE)
            {
                IApp.ShowError(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_9);
                FText_SourceFile.Focus();
                return false; // Chyba
            }

            string T = FCombo_ChecksumType.SelectedStringID;
            if ((FRadio_UseOwn.Checked) && (!IVerifyChecksumDataStruct.IsCandidate(T, FText_OwnChecksum.Text)))
            {
                IApp.ShowError(string.Format(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_10, T));
                FText_OwnChecksum.Focus();
                return false; // Chyba
            }

            if ((FRadio_UseFile.Checked))
            {
                if (FText_ChecksumFile.Text == "")
                {
                    IApp.ShowError(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_13);
                    FText_ChecksumFile.Focus();
                    return false; // Chyba
                }
                string T1, Val;
                if (!IVerifyChecksumDataStruct.ExtractChecksumFromFile(FText_ChecksumFile.Text, FText_SourceFile.Text, out T1, out Val))
                {
                    IApp.ShowError(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_11);
                    FText_ChecksumFile.Focus();
                    return false; // Chyba
                }
                if (T1 != T)
                {
                    IApp.ShowError(string.Format(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_12, T1));
                    FText_ChecksumFile.Focus();
                    return false; // Chyba
                }
            }

            return true; // Vsetko OK
        }
        /// <summary>Nacitanie obsahu formulara</summary>
        /// <param name="Result">vysledok</param>
        protected void ReadForm(IVerifyChecksumDataStruct.IVerifyChecksumItem Result)
        {
            Result.SourceFileName = FText_SourceFile.Text;
            Result.ChecksumType = FCombo_ChecksumType.SelectedStringID;
            Result.UserChecksum = FRadio_UseOwn.Checked ? FText_OwnChecksum.Text : "";
            Result.ChecksumFileName = FRadio_UseFile.Checked ? FText_ChecksumFile.Text : "";
        }

        /// <summary>Event: Click pre tlacidlo OK</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_BtnOKClick(object pSender, EventArgs e)
        {
            if (!CheckForm()) return; // Spustim test
            ReadForm(Value); // Nacitam obsah
            DialogResult = System.Windows.Forms.DialogResult.OK; // OK
        }
        /// <summary>Event: CheckedChanged</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_CheckedChanged(object pSender, EventArgs e)
        {
            UpdateFormState(); // Aktualizujem stav
        }
        /// <summary>Event: OnClick pre tlacidlo FBtn_ChooseSource</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_BtnClick_ChooseSourceFile(object pSender, EventArgs e)
        {
            string FN = IApp.ShowEditor_ChooseFileLoad(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_15, lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_14);
            if (FN != "") FText_SourceFile.Text = FN;
        }
        /// <summary>Event: OnClick pre tlacidlo FBtn_ChooseChecksumFile</summary>
        /// <param name="pSender">zdroj</param>
        /// <param name="e">parameter</param>
        protected void Event_BtnClick_ChooseChecksumFile(object pSender, EventArgs e)
        {
            string FN = IApp.ShowEditor_ChooseFileLoad(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_16, lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_17);
            if (FN == "") return; // Nic nebolo vybrane?

            string T, Val;
            if (!IVerifyChecksumDataStruct.ExtractChecksumFromFile(FN, FText_SourceFile.Text, out T, out Val))
            {
                IApp.ShowError(lang.FORM_EDIT_VERIFY_CHECKSUM_ITEM_EDIT_TEXT_18);
                return;
            }
            FCombo_ChecksumType.SelectedStringID = T; // Nastavim nacitany typ
            FText_ChecksumFile.Text = FN; // Ulozim nazov suboru
        }
    }

}
